package com.ricchieri.model;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.ricchieri.util.DateUtil;

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "price")
public class Price extends BaseEntity {
	
	private static final long serialVersionUID = 2138729290800463857L;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "price", nullable = false, insertable = false, updatable = false)
	private Trip trip;
	
	@Column(name = "cost", nullable = false)
	private double cost;
	
	@Column(name = "start", nullable = false)
	private Date start;
	
	@Column(name = "finish", nullable = false)
	private Date finish;

	public double getCost() {
		return cost;
	}

	public void setCost(double cost) {
		this.cost = cost;
	}

	public Date getStart() {
		return start;
	}

	public void setStart(Date start) {
		this.start = start;
	}

	public Date getFinish() {
		return finish;
	}

	public void setFinish(Date finish) {
		this.finish = finish;
	}

	public Trip getTrip() {
		return trip;
	}

	public void setTrip(Trip trip) {
		this.trip = trip;
	}
	
	public boolean isDateInPeriod(Date date) {
		return DateUtil.isDateBetweenDates(date, this.getStart(), this.getFinish());
	}
}
